﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x020001AF RID: 431
	public class Amplifier : OffsetModifier
	{
		// Token: 0x060008FE RID: 2302 RVA: 0x00031494 File Offset: 0x0002F894
		protected override void OnModifyOffset()
		{
			if (!this.ik.fixTransforms)
			{
				if (!Warning.logged)
				{
					Warning.Log("Amplifier needs the Fix Transforms option of the FBBIK to be set to true. Otherwise it might amplify to infinity, should the animator of the character stop because of culling.", base.transform, false);
				}
				return;
			}
			foreach (Amplifier.Body body in this.bodies)
			{
				body.Update(this.ik.solver, this.weight, base.deltaTime);
			}
		}

		// Token: 0x040005AC RID: 1452
		[Tooltip("The amplified bodies.")]
		public Amplifier.Body[] bodies;

		// Token: 0x020001B0 RID: 432
		[Serializable]
		public class Body
		{
			// Token: 0x06000900 RID: 2304 RVA: 0x00031534 File Offset: 0x0002F934
			public void Update(IKSolverFullBodyBiped solver, float w, float deltaTime)
			{
				if (this.transform == null || this.relativeTo == null)
				{
					return;
				}
				Vector3 a = this.relativeTo.InverseTransformDirection(this.transform.position - this.relativeTo.position);
				if (this.firstUpdate)
				{
					this.lastRelativePos = a;
					this.firstUpdate = false;
				}
				Vector3 vector = (a - this.lastRelativePos) / deltaTime;
				this.smoothDelta = ((this.speed > 0f) ? Vector3.Lerp(this.smoothDelta, vector, deltaTime * this.speed) : vector);
				Vector3 v = this.relativeTo.TransformDirection(this.smoothDelta);
				Vector3 a2 = V3Tools.ExtractVertical(v, solver.GetRoot().up, this.verticalWeight) + V3Tools.ExtractHorizontal(v, solver.GetRoot().up, this.horizontalWeight);
				for (int i = 0; i < this.effectorLinks.Length; i++)
				{
					solver.GetEffector(this.effectorLinks[i].effector).positionOffset += a2 * w * this.effectorLinks[i].weight;
				}
				this.lastRelativePos = a;
			}

			// Token: 0x06000901 RID: 2305 RVA: 0x00031690 File Offset: 0x0002FA90
			private static Vector3 Multiply(Vector3 v1, Vector3 v2)
			{
				v1.x *= v2.x;
				v1.y *= v2.y;
				v1.z *= v2.z;
				return v1;
			}

			// Token: 0x040005AD RID: 1453
			[Tooltip("The Transform that's motion we are reading.")]
			public Transform transform;

			// Token: 0x040005AE RID: 1454
			[Tooltip("Amplify the 'transform's' position relative to this Transform.")]
			public Transform relativeTo;

			// Token: 0x040005AF RID: 1455
			[Tooltip("Linking the body to effectors. One Body can be used to offset more than one effector.")]
			public Amplifier.Body.EffectorLink[] effectorLinks;

			// Token: 0x040005B0 RID: 1456
			[Tooltip("Amplification magnitude along the up axis of the character.")]
			public float verticalWeight = 1f;

			// Token: 0x040005B1 RID: 1457
			[Tooltip("Amplification magnitude along the horizontal axes of the character.")]
			public float horizontalWeight = 1f;

			// Token: 0x040005B2 RID: 1458
			[Tooltip("Speed of the amplifier. 0 means instant.")]
			public float speed = 3f;

			// Token: 0x040005B3 RID: 1459
			private Vector3 lastRelativePos;

			// Token: 0x040005B4 RID: 1460
			private Vector3 smoothDelta;

			// Token: 0x040005B5 RID: 1461
			private bool firstUpdate;

			// Token: 0x020001B1 RID: 433
			[Serializable]
			public class EffectorLink
			{
				// Token: 0x040005B6 RID: 1462
				[Tooltip("Type of the FBBIK effector to use")]
				public FullBodyBipedEffector effector;

				// Token: 0x040005B7 RID: 1463
				[Tooltip("Weight of using this effector")]
				public float weight;
			}
		}
	}
}
